// 动态管理 token
// 通过 pinia 管理 token
import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    token: localStorage.getItem('authorization') || null,
  }),
  actions: {
    setToken(token: string | null) {
      this.token = token;
      if (token) {
        localStorage.setItem('authorization', token);
      } else {
        localStorage.removeItem('authorization');
      }
    },
  },
});